package com.module.base.ext

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.lxj.xpopup.core.BasePopupView
import com.module.base.base.adapter.BaseVmViewHolder
import kotlinx.coroutines.flow.MutableSharedFlow

/**
 *  BasePopupView 弹窗事件监听
 */
fun <T> BasePopupView.observe(
    shareFlow: MutableSharedFlow<T>,
    delay: Long = 0,//延迟单位毫秒
    //默认onCreate时候启动协程，onDestroy时候停止协程
    state: Lifecycle.State = Lifecycle.State.CREATED,
    success: (T) -> Unit
) {
    com.module.frame.ext.observe(lifecycleScope, lifecycle, shareFlow, delay, state, success)
}

/**
 *  BaseVmViewHolder 事件监听
 */
fun <T> BaseVmViewHolder<*, *, *>.observe(
    shareFlow: MutableSharedFlow<T>,
    delay: Long = 0,//延迟单位毫秒
    //默认onCreate时候启动协程，onDestroy时候停止协程
    state: Lifecycle.State = Lifecycle.State.CREATED,
    success: (T) -> Unit
) {
    com.module.frame.ext.observe(lifecycleScope, lifecycle, shareFlow, delay, state, success)
}